﻿using AppEszköz.Xml;
using System;
namespace AppEszköz.ErrorControl
{
    public class ErrorEntry
    {
        public string UserId { get; set; } = string.Empty;

        public string ErrorCode { get; set; } = string.Empty;

        public string InnerExceptionMessage1 { get; set; } = string.Empty;

        public string InnerExceptionMessage2 { get; set; } = string.Empty;

        public string ExceptionSource { get; set; } = string.Empty;

        public string ErrorDescription { get; set; } = string.Empty;

        public string Environment { get; set; } = string.Empty;

        public string ExceptionStackTrace { get; set; } = string.Empty;

        public string ExceptionMessage { get; set; } = string.Empty;

        public DateTime ErrorDateTime { get; set; }

        public string ExceptionTargetSite { get; set; } = string.Empty;

        public ErrorEntry()
        {
        }

        public ErrorEntry(Exception ex)
        {
            if (ex == null)
                throw new ArgumentNullException("ex");
            this.ErrorDateTime = DateTime.Now;
            this.ExceptionMessage = ex.Message;
            this.ExceptionSource = ex.Source;
            this.ExceptionStackTrace = ex.StackTrace;
            if (ex.TargetSite != null)
                this.ExceptionTargetSite = ex.TargetSite.Name;
            if (ex.InnerException == null)
                return;
            this.InnerExceptionMessage1 = ex.InnerException.Message;
            if (ex.InnerException.Message == null)
                return;
            this.InnerExceptionMessage2 = ex.InnerException.InnerException.Message;
        }

        public override string ToString()
        {
            return XmlHelper.Serialize((object)this).Replace("<?xml version=\"1.0\"?>\r\n", "") + "\r\n";
        }
    }
}
